package net.wexoo.onlinedivelog.entity.dive;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import net.wexoo.onlinedivelog.entity.diveGuide.DiveGuideBean;
import net.wexoo.onlinedivelog.entity.diver.DiverBean;


/**
 * EJBDive.java - saves information about a dive
 * 
 * @author wexoo
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(of = "id")

@Entity
@Table(name = "DIVE")
public class DiveBean implements Serializable {

  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
  @SequenceGenerator(name = "generator", sequenceName = "DIVE_SEQUENCE", allocationSize=1)
  @Column(name = "ID")
  private Integer id;

  @ManyToMany(fetch = FetchType.EAGER)
  @JoinTable(name = "DIVE_MEMBER", joinColumns = @JoinColumn(name = "DIVE"), inverseJoinColumns = @JoinColumn(name = "DIVER"))
  private List<DiverBean> divers;

  @Temporal(javax.persistence.TemporalType.DATE)
  @Column(name = "DIVE_DATE")
  private Date diveDate;

  @Column(name = "MAX_DEPTH")
  private Float maxDepth;

  @Column(name = "DIVE_SITE")
  private String diveSite;

  @ManyToOne
  @JoinColumn(name = "DIVE_GUIDE")
  private DiveGuideBean diveGuide;

  public DiveBean(List<DiverBean> divers, Date diveDate, String diveSite, Float maxDepth, DiveGuideBean diveGuide) {
    this.divers = divers;
    this.diveDate = diveDate;
    this.diveSite = diveSite;
    this.maxDepth = maxDepth;
    this.diveGuide = diveGuide;
  }
}